package com.hayq.readcard.config;

import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import static com.hayq.readcard.entity.Card.defaultGetCardId;

public class CardWebSocketHandler extends TextWebSocketHandler {
    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) {
        // 接收到消息后，读取IC卡号并返回
        String msg = defaultGetCardId();
        try {
            session.sendMessage(new TextMessage(msg));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
